import Vue from "vue";

const jsbos = require("./utils/jsbos").default;

import "normalize.css/normalize.css"; // a modern alternative to CSS resets

import Element from "element-ui";
import "./styles/element-variables.scss";
import "./assets/scss/common.scss";
import "./styles/variables.css";
import "./assets/scss/global.css";

import "@/styles/index.scss"; // global css
import "./assets/scss/theme.scss"; // 主题

import App from "./App";
import store from "./store";
import router from "./router";

import i18n from "./lang"; // internationalization
import "./permission"; // permission control
import "./utils/error-log"; // error log
import { message } from "./utils/message";
import basicContainer from "./components/basic-container/main";
import { isEmpty } from "./utils/isEmpty";
import * as filters from "./filters"; // global filters
import VideoPlayer from "vue-video-player";

import "video.js/dist/video-js.css";

import "vue-video-player/src/custom-theme.css";

Vue.use(VideoPlayer);
require("./utils/rem");

Vue.prototype.$isEmpty = isEmpty;

import VScaleScreen from "v-scale-screen";
Vue.use(VScaleScreen);

// 自定义按钮权限指令
import permission from "@/directive/permission";
Vue.use(permission);
import trim from "@/directive/trim";
Vue.use(trim);
import removeAria from "@/directive/removeAria";
Vue.use(removeAria);
import JsonViewer from "vue-json-viewer";
Vue.use(JsonViewer);
// 注册全局容器
Vue.component("basicContainer", basicContainer);
import scrollTo from "@/directive/scrollTo";
Vue.use(scrollTo);

//自动指令
// Vue.directive('scrollTo', {
//   bind(el, binding) {
//     el.addEventListener('click', () => {
//       const target = document.querySelector(binding.value);
//       if (target) {
//         target.scrollIntoView({ behavior: 'smooth' });
//       }
//     });
//   }
// });

Vue.use(Element, {
  size: jsbos.storageGet("size") || "small", // set element-ui default size
  i18n: (key, value) => i18n.t(key, value),
});
// 批量引入组件
import components from "./components";
Vue.use(components);
// console.log(require('./utils/define'))
// 添加实例属性
Object.assign(Vue.prototype, {
  define: require("./utils/define").default, // 常量
  jsbos, // 公共方法
  formValidate: require("./utils/formValidate").default, // 表单验证
  $message: message,
});

// 全局注册过滤器
Object.keys(filters).forEach((key) => {
  Vue.filter(key, filters[key]);
});

Vue.config.productionTip = false;

const vm = new Vue({
  el: "#app",
  router,
  store,
  i18n,
  render: (h) => h(App),
  beforeCreate() {
    Vue.prototype.$bus = this; //安装全局事件总线
  },
});
export default vm;
